package com.yixing.tech.entity.controller;

import com.yixing.tech.common.base.BaseControl;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.common.base.Rs;
import com.yixing.tech.entity.service.IEntityService;
import com.yixing.tech.common.vo.s5.EntitiesVO;
import com.yixing.tech.common.vo.s5.EntityVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author yixing tech
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/entity")
public class EntityController extends BaseControl {

    @Resource
    IEntityService entityService;

    @PostMapping("/free/insert")
    public Rs<Object> insert(@RequestBody EntityVO vo) throws BusinessException {
        String id = entityService.insert(vo);
        return Rs.ok(id);
    }

    @PostMapping("/list/free/insert")
    public Rs<Object> batchInset(@RequestBody EntitiesVO vo) throws BusinessException {
        entityService.batchInsert(vo);
        return Rs.ok();
    }

    @PostMapping("/free/remove")
    public Rs<Object> remove(@RequestBody EntityVO vo) throws BusinessException {
        entityService.remove(vo);
        return Rs.ok();
    }

    @PostMapping("/free/update")
    public Rs<Object> update(@RequestBody EntityVO vo) throws BusinessException {
        entityService.update(vo);
        return Rs.ok();
    }

    @GetMapping("/free/wh/packControl")
    public Rs<Object> packControl(@RequestParam(value = "cartonNo") String cartonNo) throws BusinessException {
        entityService.packControl(cartonNo);
        return Rs.ok();
    }

    @GetMapping("/{planId}/left/lynums")
    public Rs<Object> getLyNums(@PathVariable String planId) throws BusinessException {
        double leftLYNums = entityService.getLeftLYNums(planId);
        return Rs.ok(leftLYNums);
    }

    @PostMapping("/{planId}/mat/left/lynums")
    public Rs<Object> getLyNums(@PathVariable String planId, @RequestBody List<Map> list) throws BusinessException {
        entityService.getLeftLYNums(planId,list);
        return Rs.ok();
    }
}
